package fr.dauphine.td3.emp;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Version;

import org.hibernate.annotations.GenericGenerator;
import org.hibernate.annotations.Parameter;
import org.hibernate.annotations.Proxy;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLUpdate;
import org.hibernate.annotations.Where;

@Entity 
@Table(name="utilisateur")
@SQLDelete(sql = "UPDATE utilisateur SET valide = 0 where id=?")
@Proxy(lazy=false)
public class Utilisateur implements Comparable {
	
	@Id
	@GeneratedValue(generator = "system-uuid")
	@GenericGenerator( name="system-uuid", strategy="uuid", parameters = {@Parameter (name="unsaved-value", value="undefined") })
	private String id = "";
	
	String login;
	String password;
	int valide;
	int administrateur;
	
	@Version
	long version;
	
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getLogin() {
		return login;
	}

	public void setLogin(String login) {
		this.login = login;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public int getValide() {
		return valide;
	}

	public void setValide(int valide) {
		this.valide = valide;
	}

	public int getAdministrateur() {
		return administrateur;
	}

	public void setAdministrateur(int administrateur) {
		this.administrateur = administrateur;
	}

	public long getVersion() {
		return version;
	}

	public void setVersion(long version) {
		this.version = version;
	}

	@Override
	public int compareTo(Object o) {
		Utilisateur u = (Utilisateur) o;
		
		return login.compareTo(u.getLogin()) + password.compareTo(u.getPassword());
	}
	
	public int hashcode() {
		return  (login.length() + password.length()) * 87 + login.hashCode() + password.hashCode();
	}
	
	@Override
	public String toString() {
		return "login: " + login + ";valide: " + valide + "; administrateur: ";
		
	}

}
